<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        let source = new ol.source.Vector({})
        let layer = new ol.layer.Vector({
            source
        })
        map.addLayer(layer)
        /* 2、创建画笔  */
        let draw = new ol.interaction.Draw({
            type: "LineString",
            source
        })
        /* 3、将画笔添加到地图 */
        // console.log(map,'map')
        map.addInteraction(draw);
        /* 监听画笔 */
        draw.on("drawend", e => {
            console.log(e, 'drawend_evt')
            // e.target是触发事件（调用函数）的那个对象，此处就是draw本身。
            // console.log(e.target === draw)// true
            // const layers_array = map.getLayers().array_
            // console.log(gaode === layers_array[0],layer===layers_array[1])// true true
            // e.feature就是被画的那个要素
            // var coordinates = e.feature.getGeometry().getCoordinates();
            const geo = e.feature.getGeometry()
            console.log(geo,'geo')
            const coordinates = geo.getCoordinates()
            console.log(coordinates, 'coordinates')
            // [Array(2), Array(2), Array(2), Array(2)] // 是一个二维数组
        })
    </script>
</body>

</html>